package com.yz.pay.schedule;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yz.model.entity.pay.PayFlow;
import com.yz.pay.service.PayService;
import com.yz.pay.service.impl.PayServiceImpl;
import com.yz.pay.utils.AlipayUtils;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.task.TaskExecutionProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:定时任务处理过期订单
 * <p>
 * User:Mr.Du
 * Date:2024/4/21
 * Time:16:40
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class PayFlowSchedule {

    private final AlipayUtils alipayUtils;

    private final ThreadPoolTaskScheduler taskScheduler;

    private final PayService payService;

    @Scheduled(cron = "0 0 8-10 * * *")
    public void test() {
        long id = Thread.currentThread().getId();
        log.info("定时任务处理过期订单开始: ");
        QueryWrapper<PayFlow> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("trade_status", "TRADE_SUCCESS")
                .and(qw -> qw.apply("TIMESTAMPDIFF(MINUTE, finish_time, NOW()) > 15"));
        List<PayFlow> list = payService.list(queryWrapper);
        log.info("定时任务处理过期订单info: " + list);
        payService.remove(queryWrapper);
        log.info("定时任务处理过期订单结束");
    }



}
